package study.rocketmq.usespringboot;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.rocketmq.vo.Order;

@RestController
public class SpringbootMQController {

    @Autowired
    SprintBootProducerService producerService;
    @RequestMapping("/send")
    public String send() throws Exception {
        Order order = new Order("123","广州");
        producerService.send(order);
        System.out.println("发送order成功："+order);
        SendResult sendResult1 =  producerService.sendTagMsg("tag");

        if(sendResult1.getSendStatus() == SendStatus.SEND_OK){
            System.out.println("发送tag成功："+sendResult1);
        }else{
            /** TODO 需要重发 */
            System.out.println("发送tag失败，有丢失数据的风险，一般要重新发送-->");
        }


        SendResult sendResult2 =   producerService.sendDelayMsg("delay",3);
        if(sendResult2.getSendStatus() == SendStatus.SEND_OK){
            System.out.println("发送Delay成功："+sendResult2);
        }else{
            /** TODO 需要重发 */
            System.out.println("发送Delay失败，有丢失数据的风险，一般要重新发送-->");
        }

        producerService.sendOrderlyMsg();
        //producerService.batchSendOrderlyMsg();
        return "发送成功！";
    }

}
